home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / allocwg.com / PROGSIZE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-11-10  |  4.5 KB  |  125 lines

  1. #ifndef MSC
  2.  
  3.     /*  Non-MSC Version  */
  4.     
  5. #if (defined(M_I86CM) || defined(M_I86LM) || defined(M_I86HM))
  6.  
  7.     /*  NOTE:  This  procedure  should only be used for
  8.                large data model programs (i.e., Compact, Large, Huge) */
  9.  
  10. #include <stddef.h>
  11. #include "alloc.h"
  12.  
  13. extern ATABLE  AllocationTable [] ; /* Provide storage for block pointers */
  14. extern SUNIT   MBSize             ; /* Default allocation block size      */
  15. extern SUNIT   NEntry             ; /* Number of table entries            */
  16. extern size_t  _asizds            ; /* Size of default data segment       */
  17. extern size_t  _abrktb []         ; /* MSC segment allocation table       */
  18. extern size_t  _psp               ; /* Segment start of program           */
  19.  
  20. ProgSize ( codesize, dataused, dataallocated, allocused, allocated)
  21.  
  22.    long  *codesize      ;  /*  Code Size              ( bytes ) */
  23.    long  *dataused      ;  /*  Data Size Used         ( bytes ) */
  24.    long  *dataallocated ;  /*  Data Size Allocated    ( bytes ) */
  25.    long  *allocused     ;  /*  Memory Allocation Used ( bytes ) */
  26.    long  *allocated     ;  /*  Memory Allocated       ( bytes ) */
  27.  
  28. /*
  29.    +---------------------------------------------------+
  30.    |                                                   |
  31.    |  This procedure attempts to determine the current |
  32.    |  size of the program (in bytes).  'Code' refers   |
  33.    |  to the actual executable code.  'Data' refers    |
  34.    |  to the default data segment (note: the data      |
  35.    |  size allocated can be controlled by setting      |
  36.    |  using the /max parameter on exemod (normally,    |
  37.    |  it is set to 65530 bytes).  The allocation       |
  38.    |  parameters refer to memory allocated via malloc  |
  39.    |  calloc, realloc, etc.                            |
  40.    |                                                   |
  41.    +---------------------------------------------------+
  42. */
  43.  
  44. {
  45.    int     i          ;
  46.    SUNIT   *hptr      ;
  47.    SUNIT   j , bsize  ;
  48.  
  49.  
  50.    *codesize      = 16L * ( (long) _abrktb [1] - (long) _psp ) ;
  51.    *dataused      = (long) _abrktb [0] ;
  52.    *dataallocated = (long) _asizds     ;
  53.    *allocused     = 0L ;
  54.    *allocated     = 0L ;
  55.  
  56.    for ( i = 0 ; i < NEntry ; i++ ) {
  57.       *allocated += (long) AllocationTable [i].Size ;
  58.       j    = (SUNIT) sizeof (HEADER) ;
  59.       while ( j < AllocationTable[i].Header->BytesUsed ) {
  60.          hptr    = (SUNIT *) AllocationTable [i].Header + j/SSIZE ;
  61.          bsize   = *hptr & ~FREE ;
  62.          j      += bsize+SSIZE   ;
  63.          if ( ! (*hptr & FREE) )
  64.            *allocused += (long) bsize ;
  65.       } ;
  66.    } ;
  67. }
  68. #endif
  69. #else
  70.  
  71.    /*  MSC Version  */
  72.  
  73. #include <stddef.h>
  74. #include <malloc.h>
  75.  
  76. extern size_t   _abrktb [] ;
  77. extern size_t   _asegh     ;
  78. extern size_t   _psp       ;
  79. extern size_t   _asizds    ;
  80.  
  81. ProgSize ( codesize, dataused, dataallocated, allocused, allocated)
  82.  
  83.    long  *codesize      ;  /*  Code Size              ( bytes ) */
  84.    long  *dataused      ;  /*  Data Size Used         ( bytes ) */
  85.    long  *dataallocated ;  /*  Data Size Allocated    ( bytes ) */
  86.    long  *allocused     ;  /*  Memory Allocation Used ( bytes ) */
  87.    long  *allocated     ;  /*  Memory Allocated       ( bytes ) */
  88.  
  89. /*
  90.    +---------------------------------------------------+
  91.    |                                                   |
  92.    |  This procedure attempts to determine the current |
  93.    |  size of the program (in bytes).  'Code' refers   |
  94.    |  to the actual executable code.  'Data' refers    |
  95.    |  to the default data segment (note: the data      |
  96.    |  size allocated can be controlled by setting      |
  97.    |  using the /max parameter on exemod (normally,    |
  98.    |  it is set to 65530 bytes).  The allocation       |
  99.    |  parameters refer to memory allocated via malloc  |
  100.    |  or calloc.                                       |
  101.    |                                                   |
  102.    +---------------------------------------------------+
  103. */
  104.  
  105. {
  106.    int        i     ;
  107.    _HEAPINFO  hinfo ;
  108.  
  109.    *codesize      = 16L * ( (long) _abrktb [1] - (long) _psp ) ;
  110.    *dataused      = (long) _abrktb [0] ;
  111.    *dataallocated = (long) _asizds     ;
  112.    *allocused     = 0L ;
  113.    *allocated     = 0L ;
  114.  
  115.    for ( i = 2 ;  _abrktb [i] != 0 && _abrktb [i+1] <= _asegh ; i += 2 )
  116.       *allocated += (long) _abrktb [i] ;
  117.  
  118.    hinfo._pentry = NULL ;
  119.    while ( _heapwalk ( &hinfo ) == _HEAPOK )
  120.      if ( hinfo._useflag == _USEDENTRY )
  121.         *allocused += (long) hinfo._size ;
  122.    return ;
  123. }
  124. #endif
  125.